<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%= title || '动物乐园管理系统' %></title>
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- Font Awesome -->
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <!-- 自定义样式 -->
  <link rel="stylesheet" href="/css/style.css">
</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <!-- 侧边栏 -->
      <% if (user) { %>
      <nav class="col-md-2 d-none d-md-block bg-light sidebar">
        <div class="sidebar-sticky">
          <div class="sidebar-header">
            <h4 class="text-center mb-4">动物乐园管理系统</h4>
          </div>
          <ul class="nav flex-column">
            <li class="nav-item">
              <a class="nav-link <%= currentPath === '/' ? 'active' : '' %>" href="/admin">
                <i class="fa fa-tachometer"></i> 仪表盘
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link <%= currentPath.includes('/users') ? 'active' : '' %>" href="/admin/users">
                <i class="fa fa-users"></i> 用户管理
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link <%= currentPath.includes('/animals') && !currentPath.includes('/images') ? 'active' : '' %>" href="/admin/animals">
                <i class="fa fa-paw"></i> 动物管理
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link <%= currentPath.includes('/categories') ? 'active' : '' %>" href="/admin/categories">
                <i class="fa fa-th-large"></i> 分类管理
              </a>
            </li>
          </ul>
          <div class="mt-auto mb-4">
            <ul class="nav flex-column">
              <li class="nav-item">
                <a class="nav-link text-danger" href="/auth/logout">
                  <i class="fa fa-sign-out"></i> 退出登录
                </a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
      <% } %>

      <!-- 主内容区 -->
      <main role="main" class="col-md-<%= user ? '10' : '12' %> ml-sm-auto px-4">
        <!-- 顶部导航栏（如果登录） -->
        <% if (user) { %>
        <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav mr-auto">
              <li class="nav-item">
                <span class="navbar-text">欢迎您，<%= user.username %></span>
              </li>
            </ul>
          </div>
        </nav>
        <% } %>

        <!-- 消息提示 -->
        <% if (success_msg && success_msg.length > 0) { %>
        <div class="alert alert-success mt-3" role="alert">
          <%- success_msg %>
        </div>
        <% } %>
        <% if (error_msg && error_msg.length > 0) { %>
        <div class="alert alert-danger mt-3" role="alert">
          <%- error_msg %>
        </div>
        <% } %>

        <!-- 页面内容 -->
        <div class="content mt-3">
          <%- body %>
        </div>
      </main>
    </div>
  </div>

  <!-- Bootstrap & jQuery JS -->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
  <!-- 自定义脚本 -->
  <script src="/js/script.js"></script>
</body>
</html>